package org.jeecg.modules.maps.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.core.constant.DataStatusEnum;
import org.jeecg.modules.maps.entity.BimMaps;
import org.jeecg.modules.maps.mapper.BimMapsMapper;
import org.jeecg.modules.maps.model.param.GeoMapsPageParam;
import org.jeecg.modules.maps.model.vo.GeoMapsVo;
import org.jeecg.modules.maps.service.IBimMapsService;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BimMapsServiceImpl extends ServiceImpl<BimMapsMapper, BimMaps> implements IBimMapsService {

    @Override
    public IPage<GeoMapsVo> findPageBySpec(GeoMapsPageParam geoMapsPageParam, Page<GeoMapsVo> page) {
        page.setRecords(baseMapper.findPageBySpec(geoMapsPageParam, page));
        return page;
    }

    @Override
    public void addItem(BimMaps bimGeoMaps) {
        //校验
        Integer count = new LambdaQueryChainWrapper<>(baseMapper)
                .eq(BimMaps::getProjectInfoId, bimGeoMaps.getProjectInfoId())
                .eq(BimMaps::getApiId, bimGeoMaps.getApiId())
                .count();
        if (count > 0) {
            throw new JeecgBootException("该项目已经配置相应apiId");
        }
        bimGeoMaps.setDelFlag(DataStatusEnum.NORMAL.getCode());
        this.save(bimGeoMaps);
    }

}
